package com.evry.marshallingtest.support;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.evry.marshallingtest.oldmodel.Customer;
import com.evry.marshallingtest.oldmodel.Database;
import com.evry.marshallingtest.oldmodel.DeliveryType;
import com.evry.marshallingtest.oldmodel.Order;
import com.evry.marshallingtest.oldmodel.Product;
import com.evry.marshallingtest.oldmodel.Products;

@Service("dataSupport")
public class DataSupport {

    public Database populateDataBase() {
        Database database = new Database();
        database.getCustomers().setCustomer(initiateCustomers());
        database.getProducts().setProduct(initiateProducts());
        database.getOrders().setOrders(initiateOrders(database));
        return database;
    }

    private List<Product> initiateProducts() {
        List<Product> products = new ArrayList<Product>();
        Product product1 = new Product();
        product1.setProductId("0001");
        product1.setDesc("Fishtank");
        product1.setPrice(40.00);
        products.add(product1);
        
        Product product2 = new Product();
        product2.setProductId("0002");
        product2.setDesc("Armchair");
        product2.setPrice(55.00);
        products.add(product2);
        
        Product product3 = new Product();
        product3.setProductId("0003");
        product3.setDesc("Bird");
        product3.setPrice(23.00);
        products.add(product3);
        return products;
    }

    private List<Order> initiateOrders(Database database) {
        List<Order> orders = new ArrayList<Order>();
        Order order1 = new Order();
        order1.setCustomer(database.getCustomers().getCustomer().get(0));
        order1.setDeliveryType(DeliveryType.EXPRESS);
        order1.setOrderNumber("O1001");
        List<Product> products = new ArrayList<Product>();
        products.add(database.getProducts().getProduct().get(0));
        products.add(database.getProducts().getProduct().get(0));
        products.add(database.getProducts().getProduct().get(2));
        Products productsObj = new Products();
        productsObj.setProduct(products);
        order1.setItems(productsObj);
        orders.add(order1);
        return orders;
    }

    private List<Customer> initiateCustomers() {    	
        List<Customer> customers = new ArrayList<Customer>();
        Customer customer1 = new Customer();
        customer1.setFirstName("Nils");
        customer1.setLastName("Karlsson");
        customer1.setPersonalCodeNumber("198104250000");
        customer1.setStreetAdress("Postvägen 15");
        customer1.setPostalAdress("Pilsnerberget");
        customer1.setPostalCode("12345");
        customers.add(customer1);
        
        Customer customer2 = new Customer();
        customer2.setFirstName("Sven");
        customer2.setLastName("Bildt");
        customer2.setPersonalCodeNumber("198503180020");
        customer2.setStreetAdress("Snusvägen 17");
        customer2.setPostalAdress("Duvnäs");
        customer2.setPostalCode("54321");
        customers.add(customer2);
        
        Customer customer3 = new Customer();
        customer3.setFirstName("Roger");
        customer3.setLastName("Limberg");
        customer3.setPersonalCodeNumber("197811102200");
        customer3.setStreetAdress("Grusvägen 32");
        customer3.setPostalAdress("Stenskottet");
        customer3.setPostalCode("39456");
        customers.add(customer3);
        return customers;
    }

}
